var date=echartUtil.GetDateStr(0);
var deptName="钉铰";
var table;
//相关业务逻辑
$(function(){
	page.bind();
	page.getDelayDate(deptName,date);
	nameToIdUtil.topGetProductionDepartment("productionDepartment");
//	page.getDelay(date);
	page.getSoonDelay(deptName);
	page.getSereven(deptName);
	echartUtil.getTopManager(deptName);
	$("#yestarday").val(date);
});


function dataChange(){
	date=$("#yestarday").val();
	table.ajax.reload( null, false);
	page.getDelay(date);
}

var page={//页面总变量
		bind:function(){
			$("#delayTable").bind("change",function(){
				deptName=$(this).val();
				page.getDelayDate(deptName,date);
				page.getSoonDelay(deptName);
				page.getSereven(deptName);
				echartUtil.getTopManager(deptName);
			});
			
			$("#isHidden").bind("click",function(){
				var text=$(this).text();
				if(text=="隐藏"){
					$(".middle").hide();
					$(this).text("显示");
				}else{
					$(".middle").show();
					$(this).text("隐藏");
				}
			});
			
			
			$("#downlodeExcle").bind("click",function(){
				var url="downlodeDalay?workShop="+deptName+"&date="+date;
				tableUtil.download(url);
			});
			
			$("#productionDepartment").bind("change",function(){
				var deptId=$("#productionDepartment").val();
				page.getDelay(deptId);
			});
		},
		getDelayDate:function(workShop,date){
			table=ajaxUtil.dataTablesAjax("dutyTable",20,"getDelayDate",
					{'workShop':workShop,'date':date},[
					{"data":"orderId",render: function (data) {
			            return "<a href='orderDetail.jsp?orderId="+data+"'>"+data+"</a>";
			          }},
					{"data":"customerId"},
					{"data":"factoryId"},
					{"data":"color"},
					{"data":"orderCount"},
					{"data":"inWorkShopTime"},
					{"data":"outWorkShopTime"},
					{"data":"delayTime"},
					{"data":"qualifiedCount"}
			]);
			
			
//			$.ajax({
//				url:"workshop/getDelayDate",
//				data:{
//					'workShop':workShop,
//					'date':date
//				},
//				success:function(data){
//				   if(data.result){
//					   data=data.data;
//					   if(data.length>0){
//						   var html="<tbody>";
//						   for(var key in data){
//							   html+="<tr><td><a class='order'>"+data[key].orderId
//						       +"</a></td><td>"+data[key].customerId
//						       +"</td><td>"+data[key].factoryId
//						       +"</td><td>"+data[key].color
//						       +"</td><td>"+data[key].orderCount
//						       +"</td><td>"+data[key].inWorkShopTime
//						       +"</td><td>"+data[key].outWorkShopTime
//						       +"</td><td>"+data[key].delayTime
//						       +"</td><td>"+data[key].qualifiedCount
//						       +"</tr>";
//						   }
//						   html+="</tbody>";
//						   $("#dutyTable tbody").html("");
//						   $("#dutyTable").append(html);
//						   aBindUtil.aOrderBind();
//					   }else{
//						   $("#dutyTable tbody").html("");
//						   layer.msg('该车间没有拖期订单', {icon: 1});
//					   }
//				   }else{
//					   layAlert(data.info);
//				   }
//				}
//			});
		},
		//即将拖期数据（三天内）
		getSoonDelay:function(workShop){
			ajaxUtil.ajaxRuquest("getSoonDelay",{'workShop':workShop},function(data){
				if(data.length>0){
					var html="<tbody>";
					for(var key in data){
						html+="<tr><td><a class='order'>"+data[key].orderId
						+"</td><td>"+data[key].factoryId
						+"</td><td>"+data[key].color
						+"</td><td>"+data[key].outWorkShopTime
						+"</tr>";
					}
					html+="</tbody>";
					$("#soonDelayTable tbody").html("");
					$("#soonDelayTable").append(html);
				}else{
					$("#soonDelayTable tbody").html("");
//					layer.msg('该车间没有即将拖期订单', {icon: 1});
				}
				aBindUtil.aOrderBind();
			});
		},
		//拖期看板
		getDelay:function(deptId){
			nameToIdUtil.topGetWorkShopNameAndId("delayTable",deptId);
			
			ajaxUtil.ajaxRuquest("getOnTime",{'date':date,"deptId":deptId},function(data){
				var userArray=new Array();
				var userDataArray=new Array();
				for(var i=0;i<data.length;i++){
					userArray.push(data[i].deptName);
					userDataArray.push(data[i].reach);
				}
				echartUtil.barChartTemp('delayBarDiv','车间准时率看板',['合格率'],userArray,userDataArray,'%');
				page.bind();
			});
		},
		//拖期看板
		getSereven:function(workShop){
			ajaxUtil.ajaxRuquest('getSereven',{'workShop':workShop},function(data){
				var userArray=new Array();
				var userDataArray=new Array();
				for(var i=0;i<data.length;i++){
					userArray.push(data[i].deptName);
					userDataArray.push(data[i].reach);
				}
				echartUtil.barChartTemp('serevenDiv','七天拖期分析表',['拖期单数'],userArray,userDataArray,'');
			});
		}
}

setInterval ("dataChange()", 900000);//十五分钟更新一次数据